#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int rank_of(const array<int, 5> &dice)
{
    int cnt[7] = {0};
    for (int x : dice)
        cnt[x]++;
    vector<int> freqs;
    for (int v = 1; v <= 6; v++)
        if (cnt[v] > 0)
            freqs.push_back(cnt[v]);
    sort(freqs.begin(), freqs.end(), greater<int>());
    // five
    if (freqs[0] == 5)
        return 8;
    // four
    if (freqs[0] == 4)
        return 7;
    // full house
    if (freqs[0] == 3 && freqs.size() == 2 && freqs[1] == 2)
        return 6;
    // straights
    // check 2-6
    bool ok = true;
    for (int v = 2; v <= 6; v++)
        if (cnt[v] != 1)
            ok = false;
    if (ok)
        return 5;
    ok = true;
    for (int v = 1; v <= 5; v++)
        if (cnt[v] != 1)
            ok = false;
    if (ok)
        return 4;
    // three
    if (freqs[0] == 3)
        return 3;
    // two pair
    if (freqs[0] == 2 && freqs.size() == 3 && freqs[1] == 2)
        return 2;
    // one pair
    if (freqs[0] == 2)
        return 1;
    return 0;
}
int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        array<int, 5> init;
        for (ll i = 0; i < 5; i++)
            cin >> init[i];

        ll cur_rank = rank_of(init);

        double best_prob = -1;
        ll best_k = 0;
        ll best_num = 0, best_den = 1;
        for (ll mask = 0; mask < 32; mask++)
        {
            vector<int> idx;
            for (ll i = 0; i < 5; i++)
            {
                if (mask & (1 << i))
                {
                    idx.push_back(i);
                }
            }
            ll k=idx.size();
            ll total=1;
            for(ll i=0;i<k;i++)
                total *= 6;
            ll win=0;
            array<int, 5> dice = init;

            function<void(int)> dfs = [&](ll pos) {
                if(pos==k)
                {
                    ll r=rank_of(dice);
                    if(r>cur_rank)
                        win++;
                    return;
                }
                ll i = idx[pos];
                for(ll d=1;d<6;d++)
                {
                    dice[i] = d;
                    dfs(pos + 1);
                }
            };
            dfs(0);
            double prob=(double)win/(double)total;
            if(prob>best_prob||(prob==best_prob&&(k<best_k)))
            {
                best_den=total;
                best_k = k;
                best_num=win;
                best_prob=prob;
            }
        }
        if (best_num == 0)
            best_den = 1;
            else{
                ll g=__gcd(best_den,best_num);
                best_num /= g, best_den /= g;
            }
            cout << best_k << " " << best_num << " " << best_den << "\n";
    }
    return 0;
}
